package com.github.ecbp.common.exception.base;


import com.github.ecbp.common.api.IErrorCode;
import com.github.ecbp.common.api.ResultCode;

public class BusinessException extends RuntimeException {
    private IErrorCode resultCode;

    public static BusinessException fail(IErrorCode respCodeAndMessageEnum) {
        return new BusinessException(respCodeAndMessageEnum);
    }

    public BusinessException() {
        super(ResultCode.SYSTEM_ERROR.getMessage());
        this.resultCode = ResultCode.SYSTEM_ERROR;
    }

    public BusinessException(IErrorCode resultCode) {
        super(resultCode.getMessage());
        this.resultCode = resultCode;
    }

    public IErrorCode getResultCode() {
        return resultCode;
    }

    public void setResultCode(ResultCode resultCode) {
        this.resultCode = resultCode;
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    protected BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public void doThrow() {
        throw this;
    }
}
